home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ktabwidget.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  8.5 KB  |  295 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2003 Stephan Binner <binner@kde.org>
  3.     Copyright (C) 2003 Zack Rusin <zack@kde.org>
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KTABWIDGET_H
  22. #define KTABWIDGET_H
  23.  
  24. #include <qtabwidget.h>
  25. #include <qstringlist.h>
  26.  
  27. #include <kdelibs_export.h>
  28.  
  29. class KTabWidgetPrivate;
  30.  
  31. /**
  32.  * \brief A widget containing multiple tabs
  33.  *
  34.  * @since 3.2
  35.  */
  36. class KDEUI_EXPORT KTabWidget : public QTabWidget
  37. {
  38.     Q_OBJECT
  39.     Q_PROPERTY( bool tabReorderingEnabled READ isTabReorderingEnabled WRITE setTabReorderingEnabled )
  40.     Q_PROPERTY( bool hoverCloseButton READ hoverCloseButton WRITE setHoverCloseButton )
  41.     Q_PROPERTY( bool hoverCloseButtonDelayed READ hoverCloseButtonDelayed WRITE setHoverCloseButtonDelayed )
  42.     Q_PROPERTY( bool tabCloseActivatePrevious READ tabCloseActivatePrevious WRITE setTabCloseActivatePrevious )
  43.     Q_PROPERTY( bool automaticResizeTabs READ automaticResizeTabs WRITE setAutomaticResizeTabs )
  44.  
  45. public:
  46.     KTabWidget( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
  47.     /**
  48.      * Destructor.
  49.      */
  50.     virtual ~KTabWidget();
  51.     /*!
  52.       Set the tab of the given widget to \a color.
  53.     */
  54.     void setTabColor( QWidget *, const QColor& color );
  55.     /*!
  56.       Returns the tab color for the given widget.
  57.     */
  58.     QColor tabColor( QWidget * ) const;
  59.  
  60.     /*!
  61.       Returns true if tab ordering with the middle mouse button
  62.       has been enabled.
  63.     */
  64.     bool isTabReorderingEnabled() const;
  65.  
  66.     /*!
  67.       Returns true if the close button is shown on tabs
  68.       when mouse is hovering over them.
  69.     */
  70.     bool hoverCloseButton() const;
  71.  
  72.     /*!
  73.       Returns true if the close button is shown on tabs
  74.       after a delay.
  75.     */
  76.     bool hoverCloseButtonDelayed() const;
  77.  
  78.     /*!
  79.       Returns true if closing the current tab activates the previous
  80.       actice tab instead of the one to the right.
  81.       @since 3.3
  82.     */
  83.     bool tabCloseActivatePrevious() const;
  84.  
  85.     /*!
  86.       Returns true if calling setTitle() will resize tabs
  87.       to the width of the tab bar.
  88.       @since 3.4
  89.     */
  90.     bool automaticResizeTabs() const;
  91.  
  92.     /*!
  93.       If \a hide is true, the tabbar is hidden along with any corner
  94.       widgets.
  95.       @since 3.4
  96.     */
  97.     void setTabBarHidden( bool hide );
  98.  
  99.     /*!
  100.       Returns true if the tabbar is hidden.
  101.       @since 3.4
  102.     */
  103.     bool isTabBarHidden() const;
  104.  
  105.     /*!
  106.       Reimplemented for internal reasons.
  107.      */
  108.     virtual void insertTab( QWidget *, const QString &, int index = -1 );
  109.  
  110.     /*!
  111.       Reimplemented for internal reasons.
  112.      */
  113.     virtual void insertTab( QWidget *child, const QIconSet& iconset,
  114.                             const QString &label, int index = -1 );
  115.     /*!
  116.       Reimplemented for internal reasons.
  117.     */
  118.     virtual void insertTab( QWidget *, QTab *, int index = -1 );
  119.  
  120.     /*!
  121.       Reimplemented for internal reasons.
  122.     */
  123.     void changeTab( QWidget *, const QString & );
  124.  
  125.     /*!
  126.       Reimplemented for internal reasons.
  127.     */
  128.     void changeTab( QWidget *child, const QIconSet& iconset, const QString &label );
  129.  
  130.     /*!
  131.       Reimplemented for internal reasons.
  132.     */
  133.     QString label( int ) const;
  134.  
  135.     /*!
  136.       Reimplemented for internal reasons.
  137.     */
  138.     QString tabLabel( QWidget * ) const;
  139.  
  140.     /*!
  141.       Reimplemented for internal reasons.
  142.     */
  143.     void setTabLabel( QWidget *, const QString & );
  144.  
  145. public slots:
  146.     /*!
  147.       Move a widget's tab from first to second specified index and emit
  148.       signal movedTab( int, int ) afterwards.
  149.     */
  150.     virtual void moveTab( int, int );
  151.  
  152.     /*!
  153.       Removes the widget, reimplemented for
  154.       internal reasons (keeping labels in sync).
  155.     */
  156.     virtual void removePage ( QWidget * w );
  157.  
  158.     /*!
  159.       If \a enable is true, tab reordering with middle button will be enabled.
  160.  
  161.       Note that once enabled you shouldn't rely on previously queried
  162.       currentPageIndex() or indexOf( QWidget * ) values anymore.
  163.  
  164.       You can connect to signal movedTab(int, int) which will notify
  165.       you from which index to which index a tab has been moved.
  166.     */
  167.     void setTabReorderingEnabled( bool enable );
  168.  
  169.     /*!
  170.       If \a enable is true, a close button will be shown on mouse hover
  171.       over tab icons which will emit signal closeRequest( QWidget * )
  172.       when pressed.
  173.     */
  174.     void setHoverCloseButton( bool enable );
  175.  
  176.     /*!
  177.       If \a delayed is true, a close button will be shown on mouse hover
  178.       over tab icons after mouse double click delay else immediately.
  179.     */
  180.     void setHoverCloseButtonDelayed( bool delayed );
  181.  
  182.     /*!
  183.       If \a previous is true, closing the current tab activates the
  184.       previous active tab instead of the one to the right.
  185.       @since 3.3
  186.     */
  187.     void setTabCloseActivatePrevious( bool previous );
  188.  
  189.     /*!
  190.       If \a enable is true, tabs will be resized to the width of the tab bar.
  191.  
  192.       Does not work reliable with "QTabWidget* foo=new KTabWidget()" and if
  193.       you change tabs via the tabbar or by accessing tabs directly.
  194.       @since 3.4
  195.     */
  196.     void setAutomaticResizeTabs( bool enable );
  197.  
  198. signals:
  199.     /*!
  200.       Connect to this and set accept to true if you can and want to decode the event.
  201.     */
  202.     void testCanDecode(const QDragMoveEvent *e, bool &accept /* result */);
  203.  
  204.     /*!
  205.       Received an event in the empty space beside tabbar. Usually creates a new tab.
  206.       This signal is only possible after testCanDecode and positive accept result.
  207.     */
  208.     void receivedDropEvent( QDropEvent * );
  209.  
  210.     /*!
  211.       Received an drop event on given widget's tab.
  212.       This signal is only possible after testCanDecode and positive accept result.
  213.     */
  214.     void receivedDropEvent( QWidget *, QDropEvent * );
  215.  
  216.     /*!
  217.       Request to start a drag operation on the given tab.
  218.     */
  219.     void initiateDrag( QWidget * );
  220.  
  221.     /*!
  222.       The right mouse button was pressed over empty space besides tabbar.
  223.     */
  224.     void contextMenu( const QPoint & );
  225.  
  226.     /*!
  227.       The right mouse button was pressed over a widget.
  228.     */
  229.     void contextMenu( QWidget *, const QPoint & );
  230.  
  231.     /*!
  232.       A tab was moved from first to second index. This signal is only
  233.       possible after you have called setTabReorderingEnabled( true ).
  234.     */
  235.     void movedTab( int, int );
  236.  
  237.     /*!
  238.       A double left mouse button click was performed over empty space besides tabbar.
  239.       @since 3.3
  240.     */
  241.     void mouseDoubleClick();
  242.  
  243.     /*!
  244.       A double left mouse button click was performed over the widget.
  245.     */
  246.     void mouseDoubleClick( QWidget * );
  247.  
  248.     /*!
  249.       A middle mouse button click was performed over empty space besides tabbar.
  250.     */
  251.     void mouseMiddleClick();
  252.  
  253.     /*!
  254.       A middle mouse button click was performed over the widget.
  255.     */
  256.     void mouseMiddleClick( QWidget * );
  257.  
  258.     /*!
  259.       The close button of a widget's tab was clicked. This signal is
  260.       only possible after you have called setHoverCloseButton( true ).
  261.     */
  262.     void closeRequest( QWidget * );
  263.  
  264. protected:
  265.     virtual void mouseDoubleClickEvent( QMouseEvent *e );
  266.     virtual void mousePressEvent( QMouseEvent * );
  267.     virtual void dragMoveEvent( QDragMoveEvent * );
  268.     virtual void dropEvent( QDropEvent * );
  269.     unsigned int tabBarWidthForMaxChars( uint maxLength );
  270. #ifndef QT_NO_WHEELEVENT
  271.     virtual void wheelEvent( QWheelEvent *e );
  272. #endif
  273.     virtual void resizeEvent( QResizeEvent * );
  274.  
  275. protected slots:
  276.     virtual void receivedDropEvent( int, QDropEvent * );
  277.     virtual void initiateDrag( int );
  278.     virtual void contextMenu( int, const QPoint & );
  279.     virtual void mouseDoubleClick( int );
  280.     virtual void mouseMiddleClick( int );
  281.     virtual void closeRequest( int );
  282. #ifndef QT_NO_WHEELEVENT
  283.     virtual void wheelDelta( int );
  284. #endif
  285.  
  286. private:
  287.     bool isEmptyTabbarSpace( const QPoint & )  const;
  288.     void resizeTabs( int changedTabIndex = -1 );
  289.     void updateTab( int index );
  290.  
  291.     KTabWidgetPrivate *d;
  292. };
  293.  
  294. #endif
  295.